GBML manual / Link Cable

link_button_held

True this frame if player `player` (1 to 4) has button `b` held down - the same question as btn_held, about any player on the link cable. Asking about your own player number reads your own buttons, so one piece of code can serve every player. A player who is not there, or a number that is not a player, is simply false.

Works differently on Game Boy - The Game Boy link cable joins two consoles, not four: players 3 and 4 are never there and read as not pressing anything, and the two consoles decide between themselves which one is player 1, so it can be a different one each time they meet.

Works differently on Game Boy Color - The Game Boy Color link cable joins two consoles, not four: players 3 and 4 are never there and read as not pressing anything, and the two consoles decide between themselves which one is player 1, so it can be a different one each time they meet.

On other consoles this differs: see Side by side and How the consoles differ.

Syntax

link_button_held(player, b) -> bool

Arguments

NameType
playerint
bbutton

Returns

bool

Description

True on every frame player player (1 to 4) is holding button b down. It is the question btn_held asks, about any player on the link cable.

Asking about your own player number gives your own buttons, with no delay, so one piece of code can serve every player. Asking about another player gives what they were pressing at their last message, about one to two frames ago.

A player who is not there, or a number that is not a player, is simply false. When a player disappears, their held buttons are let go of, so a cable pulled while someone held RIGHT can never leave RIGHT stuck down.

Example

if (link_button_held(2, BTN_RIGHT)) {
    x += 2;
}

Moves right for as long as player 2 holds RIGHT, on both consoles.

On the GBA

Players are numbered 1 to 4 by where they sit on the cable, and player 1 is the console with the cable’s small purple plug in it. Another player’s buttons arrive about one to two frames after they were pressed (your own are read straight from the buttons, with no delay), so the two consoles never agree to the frame. A player’s buttons are let go of, once, when they disappear, so "while the button is held" never gets stuck if the cable is pulled. A very short tap that arrives in the same frame as the next message still counts: pressed and released can both be true for it.

See also: link_button_pressedlink_button_releasedbtn_heldlink_dxThe link cable